using System;
using System.Collections.Generic;
using System.Text;
using AAM.BIZ;
using AAM;
using CMS.BOP;
using System.Web.Security;

namespace CMS.BIZ
{
    [DatabaseTable(TableName="Messages",TableAlias="msg")]
    public class BizMessage : BizObject
    {

        public static readonly ObjectType ObjectType = new ObjectType("BizMessage");

        private int messageID = 0;
        private int senderID = 0;
        private DateTime messageDate;
        private string messageTitle = "";
        private string messageBody = "";

        private BizMembershipUser sender = null;

        public BizMessage()
            : base(ObjectType, new object[] { 0 })
        {
        }

        [DatabaseRow(PrimaryKey=true,Identity=true)]
        public int MessageID
        {
            get { return messageID; }
            set { messageID = value; ID[0] = value; }
        }
        [DatabaseRow()]
        public int SenderID
        {
            get { return senderID; }
            set { senderID = value; }
        }
        [DatabaseRow()]
        public DateTime MessageDate
        {
            get { return messageDate; }
            set { messageDate = value; }
        }
        [DatabaseRow()]
        public string MessageTitle
        {
            get { return messageTitle; }
            set { messageTitle = value; }
        }
        [DatabaseRow()]
        public string MessageBody
        {
            get { return messageBody; }
            set { messageBody = value; }
        }

        public BizMembershipUser Sender
        {
            get
            {
                if (sender == null && senderID != 0)
                {
                    SqlBizMembershipProvider provider = (SqlBizMembershipProvider)Membership.Provider;
                    sender = (BizMembershipUser)provider.GetUser(senderID, false);
                }
                return sender;
            }
            set { sender = value; SenderID = 0; if (sender != null) senderID = sender.MemberID; }
        }
    }
}
